<template>
  <div class="backgroundBox">
    <div class="formBox">
      <div class="logoBox">
        <img
          src="https://likede2-admin.itheima.net/img/logo.595745bd.png"
          alt=""
        />
      </div>
      <el-form
        :model="ruleForm"
        status-icon
        :rules="rules"
        ref="ruleForm"
        class="demo-ruleForm"
      >
        <el-form-item prop="uname">
          <el-input
            type="uname"
            v-model="ruleForm.uname"
            autocomplete="off"
            placeholder="请输入用户名"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            type="password"
            v-model="ruleForm.password"
            autocomplete="off"
            show-password
            placeholder="请输入密码"
          ></el-input>
        </el-form-item>

        <el-form-item prop="yzm">
          <el-input v-model="ruleForm.yzm" placeholder="请输入验证码">
          </el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitForm()" style="width: 100%">
            登录</el-button
          >
        </el-form-item>
        <div class="yamBoxy" @click="getYzm()">
          <img :src="`https://likede2-java.itheima.net/api/user-service/user/imageCode/${clientToken}`" alt="" />
        </div>
        <i class="el-icon-lock"></i>
        <i class="el-icon-mobile"></i>
        <i class="el-icon-smoking"></i>
      </el-form>
    </div>
  </div>
</template>

<script>
import yzm from '@/Utils/yzm'
export default {
  data () {
    return {
      ruleForm: {
        uname: 'admin',
        password: 'admin',
        yzm: ''
      },
      rules: {
        uname: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
        yzm: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
      },
      src: '',
      clientToken: ''
    }
  },
  methods: {
    async submitForm () {
      await this.$refs.ruleForm.validate()
      await this.$store.dispatch('user/asyncLogin', {
        clientToken: this.clientToken,
        code: this.ruleForm.yzm,
        loginName: this.ruleForm.uname,
        password: this.ruleForm.password,
        loginType: 0
      })
    },
    getYzm () {
      this.clientToken = yzm()
    }
  },
  created () {
    this.getYzm()
  }
}
</script>

<style>
* {
  margin: 0;
  padding: 0;
}

</style>
<style lang="less" scoped>
::v-deep .el-input__inner {
  padding-left: 34px;
  height: 52px;
}
.yamBoxy {
  position: absolute;
  bottom: 88px;
  right: 50px;
  border-radius: 4px;
  width: 100px;
  height: 52px;
  background-color: #ff8c8c;
}
.el-form,
.demo-ruleForm {
  margin: 100px 50px;
}
.backgroundBox {
  position: relative;
  height: 100vh;
  width: 100vw;
  background-image: url(https://likede2-admin.itheima.net/img/background.be4fae7d.png);
  background-size: 100%;
}
.formBox {
  position: relative;
  position: absolute;
  top: 50%;
  left: 50%;
  margin-top: -194px;
  margin-left: -259px;
  width: 518px;
  height: 388px;
  background-color: #fff;
  box-shadow: 0 3px 70px 0 rgba(30, 111, 72, 0.35);
  border-radius: 10px;
}
.el-icon-lock {
  position: absolute;
  top: 192px;
  left: 62px;
}
.el-icon-mobile {
  position: absolute;
  top: 118px;
  left: 62px;
}
.el-icon-smoking {
  position: absolute;
  top: 267px;
  left: 62px;
}
.logoBox {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 96px;
  height: 96px;
}
img {
  width: 100%;
  height: 100%;
  overflow: hidden;
}
</style>
